<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录界面</title>
    <script src="js/jquery3.6.4.js"></script>
    <script>
        $(function () {
            $("#myForm").submit(function (event) {
                event.preventDefault();

                const formData = {
                    name: $("#name").val(),
                    password: $("#pwd").val()
                };

                $.ajax({
                    url: "login",
                    type: "POST",
                    data: formData,
                    dataType: "json",
                    success: function (data) {
                        if (data.code === "0000") {
                            // 登录成功，重定向到指定页面
                            window.location.href = "queryEmp";
                        } else {
                            // 登录失败，显示错误信息
                            $("#error-message").text(data.msg);
                        }
                    }
                });
            });
        });
    </script>
</head>
<body>
<h6 id="error-message" style="color: red;"></h6>
<form action="login" method="post" id="myForm">
    <label for="name">用户名:</label>
    <input type="text" id="name" name="name"/>
    <br/>
    <label for="pwd">密码:</label>
    <input type="password" id="pwd" name="password"/>
    <br/>
    <input type="submit" value="登录"/>
    <input type="button" value="注册" onclick="location.href='register.jsp'"/>
    <input type="reset" value="取消"/>
</form>
</body>
</html>
